package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo4 {
    public static void main(String[] args) {
        try (
            Connection connection=DBUtil.getConnection();
        ){
            String sql="select s.name sname,s.age sage,s.gender sgender,c.name cname,t.name tname " +
                    "from student s " +
                    "join class c on c.id = s.class_id " +
                    "join teacher t on t.id= c.teacher_id " +
                    "where c.name='1年级1班' ";
            Statement state=connection.createStatement();
            ResultSet rs=state.executeQuery(sql);
            while (rs.next()){
                String sname=rs.getString("sname");
                int sage=rs.getInt("sage");
                String sgender=rs.getString("sgender");
                String cname=rs.getString("cname");
                String tname=rs.getString("tname");
                System.out.println(sname+","+sage+","+sgender+","+cname+","+tname);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
